<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="start_time" id="start_time"  placeholder="yyyy-MM" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="end_time" id="end_time"  placeholder="yyyy-MM" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layui-col-md12" style="margin-top:20px;">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div id="echarts-records" style="width: 100%;min-height:500px"></div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'table','laydate','echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            echarts = layui.echarts,
            laydate=layui.laydate;
        // 上架开始日期
        var insShelf = laydate.render({
            elem: '#start_time',
            calendar: true,
            type: 'month',
            done: function (value, date) {
                //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insUnder.config.elem[0].focus();
            }
        });
        //上架结束日期
        var insUnder = laydate.render({
            elem: '#end_time',
            calendar: true,
            type: 'month',
            done: function (value, date) {
                //更新开始日期的最大日期
                insShelf.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            roulette_static(data.field.start_time,data.field.end_time);
            return false;
        });

        var active_id="{$active_id}";
        var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');
        roulette_static();
        // echarts 窗口缩放自适应
        window.onresize = function(){
            echartsRecords.resize();
        }
        /**
         * 报表功能
         */
        function roulette_static(start_time='',end_time='')
        {

            $.ajax({
              url:'/admin/Active/roulette_static?action=ajax&active_id='+active_id,
                type:'post',
                dataType:'json',
                data:{
                    start_time,
                    end_time
                },
                success:function(res){
                  if(res.status){
                      var optionRecords = {
                          tooltip: {
                              trigger: 'axis'
                          },
                          legend: {
                              data:res.data.title_array
                          },
                          grid: {
                              left: '3%',
                              right: '4%',
                              bottom: '3%',
                              containLabel: true
                          },
                          toolbox: {
                              feature: {
                                  saveAsImage: {}
                              }
                          },
                          xAxis: {
                              type: 'category',
                              boundaryGap: false,
                              data: res.data.date_array
                          },
                          yAxis: {
                              type: 'value'
                          },
                          series:res.data.data_array
                      };
                      echartsRecords.setOption(optionRecords);
                  }

                }
            });

        }
    });
</script>

</body>
</html>